package 力扣.二分;

public class 回文数9 {
    public static void main(String[] args) {
        int x=0;
        boolean b = isPalindrome2(x);
        System.out.println(b);
    }
    public static boolean isPalindrome(int x) {
        if (x<0){
            return false;
        }
        String s=x+"";
        int length = s.length();
        int mid=0;
        if (length %2 != 0){
            mid=length/2+1;
        }else{
            mid=length/2;
        }
        for (int i = 0; i < mid ; i++) {
                int start = s.charAt(i);
                int end=s.charAt(length-1-i);
                if (start != end){
                    return false;
                }
            }
        return true;
    }
    public static boolean isPalindrome2(int x) {
        if (x < 0 || (x%10 == 0 && x!=0)) {//第二个条件防止了以0为结尾的数字 如10 100
            return false;
        }
        int newx=0;
        while (x>newx){
            newx = newx*10 + x%10;
            x/=10;
        }
        return x == newx || x == newx/10; //奇偶个数
    }
}
